package com.pentalog.stock.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.pentalog.stock.dao.StockDao;
import com.pentalog.stock.model.Stock;

@Repository("stockDao")
public class StockDaoImpl extends BaseDAO implements StockDao {

	public void save(Stock stock) {
		getHibernateTemplate().save(stock);
	}

	public void update(Stock stock) {
		getHibernateTemplate().update(stock);
	}

	public void delete(Stock stock) {
		getHibernateTemplate().delete(stock);
	}

	@SuppressWarnings("unchecked")
	public Stock findByStockCode(String stockCode) {
		List<Stock> list = getHibernateTemplate().find(
				"from Stock where stockCode=?", stockCode);
		if (list != null & !list.isEmpty()) {
			return list.get(0);
		} else {
			return null;
		}
	}

}